#!/usr/bin/python3
# -*- coding: utf-8 -*-

import allure
from playwright.sync_api import Page

from models.base_page import BasePage
from models.login_page.login_page import LoginPage
from utils.log import log


class AccountBusiness(BasePage):
    def __init__(self, page: Page):
        super().__init__(page)
        self.login_page = LoginPage(self.page)

    @allure.step("登录")
    def login(self, username: str, password: str) -> str:
        """登录业务"""
        log.info(f"登录用户名:{username},密码:{password}")
        self.login_page.navigate()
        self.login_page.fill_username(username)
        self.login_page.fill_password(password)
        self.login_page.click_login_button()
        self.page.wait_for_timeout(15000)
        title = self.page.title()
        log.info(f"执行登录操作后,title为:{title}")
        return title
